package com.yunkuhui.www.demo.configuration;

import com.yunkuhui.www.demo.conf.RedisConf;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
@AutoConfigureAfter({RedisAutoConfiguration.class})
public class RedisConfiguration {

	private RedisConf[] redisConf;

	@Autowired
	public RedisConfiguration(@NotNull RedisConf redisConf) {
		this.redisConf = redisConf.getRedisConf();
	}

	@Bean(name = "redisTemplate0")
	RedisTemplate redisTemplate0() {
		return redisConf[0].getRedisTemplate();
	}

	@Bean(name = "redisTemplate1")
	RedisTemplate redisTemplate1() {
		return redisConf[1].getRedisTemplate();
	}

	@Bean(name = "redisTemplate2")
	RedisTemplate redisTemplate2() {
		return redisConf[2].getRedisTemplate();
	}
}
